package dolf.objects;
import dolf.game.*;
import dolf.objects.WorldObject;
import dolf.objects.Ball;
import dolf.objects.CircleObject;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;

import dolf.window.*;

public class Hole extends CircleObject implements java.io.Serializable, GroundObject{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private transient java.awt.Image overlay;
	
	
	public Hole(Point pos){
		super(pos, 10, false,true);
		overlay = ImageStore.getInstance().getImage("dolf/gfx/environment/hole.png");
		overlay = overlay.getScaledInstance(2*this.getRadius(), 2*this.getRadius(), Image.SCALE_SMOOTH);
		this.setMass(100);
		this.setMotion(new Vector(0,0));
	}
	public void paint(Graphics2D g){
		Color tmp = g.getColor();
		g.setColor(Color.DARK_GRAY);
		g.fillOval(this.getPosition().getIntX() - this.getRadius(), this.getPosition().getIntY() - this.getRadius(), 2*this.getRadius(),2*this.getRadius());
		if (overlay == null) {
	       	overlay = ImageStore.getInstance().getImage("dolf/gfx/environment/hole.png");
	    	overlay = overlay.getScaledInstance(2*this.getRadius(), 2*this.getRadius(), Image.SCALE_SMOOTH);
	    }
		g.drawImage(overlay, this.getPosition().getIntX()-this.getRadius(), this.getPosition().getIntY()-this.getRadius(), 2*this.getRadius(), 2*this.getRadius(),null);
		g.setColor(tmp);
	}
	
	public double MoveOver(WorldObject obj, double percent){
		if(obj instanceof Ball){
			Ball b = (Ball) obj;
			//obj.setMotion(obj.getMotion().setLength(obj.getMaxSpeed()-dist));
			if(b.getPosition().getDist(this.getPosition())<7 && b.getMotion().getLength()<2){
				b.getPlayer().setPocketed(true);
				PlayerDisplay.getInstance().draw();
				Level.getInstance().removePlayer(b.getPlayer());
			} else {
				//System.out.println("percent :"+percent);
				Vector tmp = b.getMotion().setLength(b.getMotion().getLength()*percent);
				b.setPosition(b.getPosition().add(tmp));
			}
		}
		return 0;
	}	
	
	public boolean newMotion(WorldObject object){
		System.out.println("sollte nicht sein!!!!!!!!!!!");
		if(object instanceof Ball){
			Ball obj = (Ball) object;
			//obj.setMotion(obj.getMotion().setLength(obj.getMaxSpeed()-dist));
			if(obj.getPosition().getDist(this.getPosition())<obj.getRadius() && obj.getMotion().getLength()<2){
				if(Level.getInstance().getAktualPlayer()== obj.getPlayer() && Level.getInstance().getAktualPlayer().getAktWeapon() != null){
					Level.getInstance().getAktualPlayer().getAktWeapon().remove();
				}
				obj.getPlayer().setPocketed(true);
				PlayerDisplay.getInstance().draw();
				Level.getInstance().removePlayer(obj.getPlayer());
				return false;
			}
		}
		return true;
	}
}
